package com.wms.web.action.system;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.wms.data.domain.service.SystemUserService;
import com.wms.data.pojo.SystemUser;
import com.wms.web.action.AbstractAction;

@ParentPackage("wms")
@Namespace("/app")
@Result(name="exception", location="/WEB-INF/jsp/common/error.jsp")
@ExceptionMappings(@ExceptionMapping(exception="java.lang.Exception", result="exception"))
public class SystemUserAction extends AbstractAction {

	private static final long serialVersionUID = 1L;
	
	@Autowired
	private SystemUserService systemUserService;
	
	private SystemUser systemUser;
	
	private String systemUserId;
	
	/**
	 * SystemUser list.
	 *
	 * <pre>
	 * 	init Login
	 * </pre>
	 *
	 * @return String
	 */
	@Action(value="systemUserList", results={@Result(name="success", location="/WEB-INF/jsp/system/system_user/system_user_list.jsp")})
	public String initSystemUserList() {
		
		return SUCCESS;
	}
	
	@Action(value="systemUserNew", results={@Result(name="success", location="/WEB-INF/jsp/system/system_user/system_user_edit.jsp")})
	public String initNew() {
		
		return SUCCESS;
	}
	
	@Action(value="systemUserEdit", results={@Result(name="success", location="/WEB-INF/jsp/system/system_user/system_user_edit.jsp")})
	public String initEdit() {
		
		setSystemUser(systemUserService.findById(getSystemUserId()));
		
		return SUCCESS;
	}
	
	@Action(value="systemUserSave", results={@Result(name="success", location="/WEB-INF/jsp/system/system_user/system_user_edit.jsp")})
	public String save() {
		
		systemUserService.saveSystemUser(getSystemUser());
		
		return SUCCESS;
	}
	
	@Action(value="systemUserAjaxDelete")
	public String ajaxDelete() {
		
		System.out.println(getSystemUserId());
		
		systemUserService.deleteById(getSystemUserId());
		
		return SUCCESS;
	}

	public SystemUser getSystemUser() {
		return systemUser;
	}

	public void setSystemUser(SystemUser systemUser) {
		this.systemUser = systemUser;
	}

	public String getSystemUserId() {
		return systemUserId;
	}

	public void setSystemUserId(String systemUserId) {
		this.systemUserId = systemUserId;
	}
}